import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _class;

import React, { PureComponent } from 'react';
import { Modal, Table, Checkbox } from 'antd';
import { Bind } from 'lodash-decorators';
import intl from 'utils/intl';
import { enableRender, TagRender } from 'utils/renderer';
import notification from 'utils/notification';
import { tableScrollWidth } from 'utils/utils';
import Icons from 'components/Icons';
import styles from "../index.less?modules";
var modelPrompt = 'ciam.menuConfig.model.menuConfig';
var commonPrompt = 'cpaas.common';
var menuIconStyle = {
  width: 14,
  height: 14,
  lineHeight: '14px'
};
var MenuExport = (_dec = Bind(), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), (_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(MenuExport, _PureComponent);

  var _super = _createSuper(MenuExport);

  function MenuExport() {
    var _this;

    _classCallCheck(this, MenuExport);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.state = {
      setIdList: []
    };
    return _this;
  }

  _createClass(MenuExport, [{
    key: "handleCancel",
    value:
    /**
     * 取消
     */
    function handleCancel() {
      var _this$props$onCancel = this.props.onCancel,
          onCancel = _this$props$onCancel === void 0 ? function (e) {
        return e;
      } : _this$props$onCancel;
      onCancel();
    }
    /**
     * 导出
     */

  }, {
    key: "handleOk",
    value: function handleOk() {
      var _this$props = this.props,
          _this$props$rowSelect = _this$props.rowSelection,
          rowSelection = _this$props$rowSelect === void 0 ? {} : _this$props$rowSelect,
          _this$props$onExport = _this$props.onExport,
          onExport = _this$props$onExport === void 0 ? function (e) {
        return e;
      } : _this$props$onExport;

      if (rowSelection.selectedRowKeys.length) {
        onExport();
      } else {
        notification.warning({
          message: intl.get('ciam.menuConfig.view.message.export.warning').d('请至少选择一行数据')
        });
      }
    }
  }, {
    key: "onCell",
    value: function onCell() {
      return {
        style: {
          overflow: 'hidden',
          maxWidth: 220,
          textOverflow: 'ellipsis',
          whiteSpace: 'nowrap'
        },
        onClick: function onClick(e) {
          var target = e.target;

          if (target.style.whiteSpace === 'normal') {
            target.style.whiteSpace = 'nowrap';
          } else {
            target.style.whiteSpace = 'normal';
          }
        }
      };
    }
  }, {
    key: "operationRender",
    value: function operationRender(text, record) {
      var _this2 = this;

      var _this$state$setIdList = this.state.setIdList,
          setIdList = _this$state$setIdList === void 0 ? [] : _this$state$setIdList;
      var checkboxProps = {
        indeterminate: record.checkedFlag === 'P',
        checked: setIdList.find(function (item) {
          return item === record.id;
        }),
        onChange: function onChange() {
          return _this2.handleCheckboxChange(record);
        }
      };
      return /*#__PURE__*/React.createElement(Checkbox, checkboxProps);
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          visible = _this$props2.visible,
          loading = _this$props2.loading,
          _this$props2$menuType = _this$props2.menuTypeList,
          menuTypeList = _this$props2$menuType === void 0 ? [] : _this$props2$menuType,
          rowSelection = _this$props2.rowSelection,
          dataSource = _this$props2.dataSource,
          confirmLoading = _this$props2.confirmLoading;
      var columns = [{
        title: intl.get("".concat(modelPrompt, ".name")).d('目录/菜单'),
        dataIndex: 'name',
        fixed: 'left',
        width: 200
      }, {
        title: intl.get("".concat(modelPrompt, ".parentName")).d('上级目录'),
        width: 120,
        dataIndex: 'parentName'
      }, {
        title: intl.get("".concat(modelPrompt, ".quickIndex")).d('快速索引'),
        width: 120,
        dataIndex: 'quickIndex'
      }, {
        title: intl.get("".concat(modelPrompt, ".icon")).d('图标'),
        width: 60,
        dataIndex: 'icon',
        render: function render(code) {
          return /*#__PURE__*/React.createElement(Icons, {
            type: code,
            size: 14,
            style: menuIconStyle
          });
        }
      }, {
        title: intl.get("".concat(modelPrompt, ".code")).d('编码'),
        dataIndex: 'code',
        onCell: this.onCell.bind(this)
      }, {
        title: intl.get("".concat(modelPrompt, ".menuType")).d('类型'),
        dataIndex: 'type',
        width: 120,
        render: function render(value) {
          var statusList = menuTypeList.map(function (item) {
            return {
              status: item.value,
              color: item.value === 'root' ? 'blue' : item.value === 'dir' ? 'green' : item.value === 'menu' ? 'orange' : 'purple',
              text: item.meaning
            };
          });
          return TagRender(value, statusList);
        }
      }, {
        title: intl.get("".concat(modelPrompt, ".sort")).d('序号'),
        dataIndex: 'sort',
        width: 60
      }, {
        title: intl.get("".concat(modelPrompt, ".description")).d('描述'),
        dataIndex: 'description',
        width: 200,
        onCell: this.onCell.bind(this)
      }, {
        title: intl.get("".concat(commonPrompt, ".status")).d('状态'),
        dataIndex: 'enabledFlag',
        width: 120,
        render: enableRender
      }];
      var tableProps = {
        loading: loading,
        dataSource: dataSource,
        columns: columns,
        rowKey: 'id',
        pagination: false,
        bordered: true,
        childrenColumnName: 'subMenus',
        scroll: {
          x: tableScrollWidth(columns)
        },
        rowSelection: rowSelection,
        className: styles['ciam-menu-config-export']
      };
      return /*#__PURE__*/React.createElement(Modal, {
        width: 900,
        title: intl.get('ciam.menuConfig.view.message.title.exportMenu').d('导出客户化菜单'),
        wrapClassName: "ant-modal-sidebar-right",
        transitionName: "move-right",
        visible: visible,
        onOk: this.handleOk,
        onCancel: this.handleCancel,
        confirmLoading: confirmLoading,
        destroyOnClose: true
      }, /*#__PURE__*/React.createElement(Table, tableProps));
    }
  }]);

  return MenuExport;
}(PureComponent), (_applyDecoratedDescriptor(_class.prototype, "handleCancel", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "handleCancel"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleOk", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "handleOk"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "onCell", [_dec3], Object.getOwnPropertyDescriptor(_class.prototype, "onCell"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "operationRender", [_dec4], Object.getOwnPropertyDescriptor(_class.prototype, "operationRender"), _class.prototype)), _class));
export { MenuExport as default };